<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>计数器</title>
</head>
<body>
    <div id="app">
        <input type="button" value="-" @click="sub">
        <span>{{num}}</span>
        <input type="button" value="+" @click="add">
    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue"></script>
    <script>
        let app = new Vue({
            el:"#app",
            data:{
                num:0
            },
            methods:{
                sub:function () {
                    if (this.num > 0){
                        this.num --;
                    }else {
                        alert("已经到底了!")
                    }
                },
                add:function () {
                    if(this.num < 10){
                        this.num ++;
                    }else {
                        alert("不能再加了！")
                    }
                }
            }
        })
    </script>
</body>
</html>